//
//  ByFootBalllListValueView.m
//  caipiao_ios
//
//  Created by mc on 2018/7/23.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByFootBalllListValueView.h"
#import "ByValueView.h"
#import "ByFootBallTitleValueView.h"

@implementation ByFootBalllListValueView

- (id)init{
    self = [super init];
    if (self) {
       
    }
    return self;
}

- (void)setType:(NSInteger)type{// 0 混合投注 1 胜平负 2 让球胜平负  3 总进球 4 比分 5半全场
    _type = type;
}

- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    CGFloat Width = SCREEN_WIDTH - 36 - 30 - 15 * 2;
    
    
    if (self.type == 0){
        
        self.backgroundColor = rgba(246, 246, 246, 1);
        self.layer.borderWidth = 1;
        self.layer.borderColor = [UIColor lightGrayColor].CGColor;
        
        CGFloat top = 10;
        for (int i = 0; i < 5; i++){
            ByFootBallTitleValueView *titleValueView = [[ByFootBallTitleValueView alloc] init];
            [self addSubview:titleValueView];
            if (i == 0) {
                titleValueView.type = 1;
                titleValueView.valueLabel.text = netModel.selectedSpfString;
                [titleValueView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(10);
                    make.right.equalTo(self).offset(0);
                    make.top.equalTo(self).offset(top);
                    make.height.mas_equalTo(@([ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedSpfString]));
                }];
                if (netModel.selectedSpfString.length == 0) {
                    titleValueView.hidden = YES;
                }
                top = top + [ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedSpfString];
                
            }else if (i == 1){
                titleValueView.type = 2;
                titleValueView.valueLabel.text = netModel.selectedRSpfString;
                [titleValueView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(10);
                    make.right.equalTo(self).offset(0);
                    make.top.equalTo(self).offset(top);
                    make.height.mas_equalTo(@([ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedRSpfString]));
                }];
                if (netModel.selectedRSpfString.length == 0) {
                    titleValueView.hidden = YES;
                }
                top = top + [ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedRSpfString];
            }else if (i == 2){
                
                titleValueView.type = 4;
                titleValueView.valueLabel.text = netModel.selectedScoresString;
                [titleValueView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(10);
                    make.right.equalTo(self).offset(0);
                    make.top.equalTo(self).offset(top);
                    make.height.mas_equalTo(@([ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedScoresString]));
                }];
                if (netModel.selectedScoresString.length == 0) {
                    titleValueView.hidden = YES;
                }
                top = top + [ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedScoresString];
                
            }else if (i == 3){
                titleValueView.type = 3;
                titleValueView.valueLabel.text = netModel.selectedGoalsString;
                [titleValueView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(10);
                    make.right.equalTo(self).offset(0);
                    make.top.equalTo(self).offset(top);
                    make.height.mas_equalTo(@([ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedGoalsString]));
                }];
                if (netModel.selectedGoalsString.length == 0) {
                    titleValueView.hidden = YES;
                }
                top = top + [ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedGoalsString];
            }else if (i == 4){
                titleValueView.type = 5;
                titleValueView.valueLabel.text = netModel.selectedHalfAllString;
                [titleValueView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(10);
                    make.right.equalTo(self).offset(0);
                    make.top.equalTo(self).offset(top);
                    make.height.mas_equalTo(@([ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedHalfAllString]));
                }];
                if (netModel.selectedHalfAllString.length == 0) {
                    titleValueView.hidden = YES;
                }
                top = top + [ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedHalfAllString];
                
            }
            
        }
        
        
    }else if (self.type == 1 || self.type == 2){
        
        ByNetModel *netModel1;
        ByNetModel *netModel2;
        ByNetModel *netModel3;
        if (self.type == 1){
            netModel1 = [netModel.spfArray firstObject];
            netModel2 = [netModel.spfArray objectAtIndex:1];
            netModel3 = [netModel.spfArray objectAtIndex:2];
        }else{
            netModel1 = [netModel.rspfArray firstObject];
            netModel2 = [netModel.rspfArray objectAtIndex:1];
            netModel3 = [netModel.rspfArray objectAtIndex:2];
        }
        ByValueView *centerView = [[ByValueView alloc] init];
        [self addSubview:centerView];
        [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self).offset(0);
            make.top.equalTo(self).offset(0);
            make.bottom.equalTo(self).offset(0);
            make.width.mas_equalTo(@50);
        }];
        centerView.titleLabel.text = netModel2.title;
        centerView.valueLabel.text = netModel2.valueString;
        centerView.netModel = netModel2;
        
        ByValueView *leftView = [[ByValueView alloc] init];
        [self addSubview:leftView];
        [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(0);
            make.right.equalTo(centerView.mas_left).offset(-20);
            make.top.equalTo(self).offset(0);
            make.bottom.equalTo(self).offset(0);
        }];
       
        leftView.titleLabel.text = netModel1.title;
        leftView.valueLabel.text = netModel1.valueString;
        leftView.netModel = netModel1;
        
        ByValueView *rightView = [[ByValueView alloc] init];
        [self addSubview:rightView];
        [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self).offset(0);
            make.left.equalTo(centerView.mas_right).offset(20);
            make.top.equalTo(self).offset(0);
            make.bottom.equalTo(self).offset(0);
        }];
       
        rightView.titleLabel.text = netModel3.title;
        rightView.valueLabel.text = netModel3.valueString;
        rightView.netModel = netModel3;
        
    }else if (self.type == 3){
        
        
        NSString *string = @"";
        for (ByNetModel *model in netModel.selectedGoalsArray) {
            string = [NSString stringWithFormat:@"%@ %@(%@) ",string ,model.title,model.valueString];
        }
        UILabel *valueLabel = [[UILabel alloc] init];
        [self addSubview:valueLabel];
        [valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10);
            make.right.equalTo(self).offset(-10);
            make.bottom.equalTo(self).offset(-5);
            make.top.equalTo(self).offset(5);
        }];
        valueLabel.textAlignment = NSTextAlignmentCenter;
        valueLabel.font = FONT(12);
        valueLabel.textColor = BY_THEME_COLOR;
        valueLabel.numberOfLines = 0;
        valueLabel.text = string;
        
    }else if (self.type == 4){
        self.backgroundColor = rgba(246, 246, 246, 1);
        self.layer.borderWidth = 1;
        self.layer.borderColor = [UIColor lightGrayColor].CGColor;
        
        CGFloat top = 10;
        for (int i = 0; i < 3; i++){
            ByFootBallTitleValueView *titleValueView = [[ByFootBallTitleValueView alloc] init];
            [self addSubview:titleValueView];
            if (i == 0) {
                titleValueView.titleLabel.text = @"胜:";
                titleValueView.valueLabel.text = netModel.selectedSScoresString;
                [titleValueView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(10);
                    make.right.equalTo(self).offset(0);
                    make.top.equalTo(self).offset(top);
                    make.height.mas_equalTo(@([ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedSScoresString]));
                }];
                top = top + [ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedSScoresString];
                
            }else if (i == 1){
                titleValueView.titleLabel.text = @"平:";
                titleValueView.valueLabel.text = netModel.selectedPScoresString;
                [titleValueView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(10);
                    make.right.equalTo(self).offset(0);
                    make.top.equalTo(self).offset(top);
                    make.height.mas_equalTo(@([ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedPScoresString]));
                }];
                top = top + [ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedPScoresString];
            }else if (i == 2){
                
                titleValueView.titleLabel.text = @"负:";
                titleValueView.valueLabel.text = netModel.selectedFScoresString;
                [titleValueView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self).offset(10);
                    make.right.equalTo(self).offset(0);
                    make.top.equalTo(self).offset(top);
                    make.height.mas_equalTo(@([ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedFScoresString]));
                }];
                top = top + [ByFootBallTitleValueView  getHeightWithDataString:netModel.selectedFScoresString];
                
            }
        }
        
    }else if (self.type == 5){
        
        UIView *buttonsView = [[UIView alloc] init];
        [self addSubview:buttonsView];
        [buttonsView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(0);
            make.right.equalTo(self).offset(0);
            make.top.equalTo(self).offset(0);
            make.bottom.equalTo(self).offset(0);
        }];
        buttonsView.backgroundColor = BY_LINE_COLOR;
        
        CGFloat left = 1;
        CGFloat magin = 1;
        CGFloat width = (Width - left * 4) / 3.0;
        CGFloat height = 45;
        
        for (int i = 0;i < 9; i++) {
            ByNetModel *netModel = [_netModel.halfAllArray objectAtIndex:i];
            UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(1 + i % 3 * (width + magin),1 + i / 3 * (height + magin), width,height)];
            [buttonsView addSubview:valueLabel];
            if (i % 3 == 0) {
                valueLabel.text = [NSString stringWithFormat:@"主胜 %d",i];
            }else if (i % 3 == 1){
                valueLabel.text = [NSString stringWithFormat:@"平 %d",i];
            }else if (i % 3 == 2){
                valueLabel.text = [NSString stringWithFormat:@"客胜 %d",i];
            }
            
            valueLabel.tag = 100 + i;
            valueLabel.font = FONT(14);
            valueLabel.textAlignment = NSTextAlignmentCenter;
        if (!netModel.selected) {
            valueLabel.textColor = [UIColor lightGrayColor];
            valueLabel.backgroundColor = [UIColor whiteColor];
        }else{
            valueLabel.textColor = [UIColor whiteColor];
            valueLabel.backgroundColor = BY_THEME_COLOR;
        }
            
        }
        
    }
}


@end
